<?php
namespace Agent\Controller;

use Utuo\BackgroundController;

class AgentOrderSettleController extends BackgroundController {
    
    protected $status = array(
        '0' => "未结算", 
        '1' => "已结算"
    );
    
	// 初始化
	public function _initialize() {
		$this->setControllerTitle('');
		$this->setActionTitle(array(
				'index' => '结算列表',
		));
		$this->setActionNav(array(
				'index',
		));
		foreach( $this->status as $k => $v ) {
		    $this->setLinkNav($v, __CONTROLLER__."/index?status={$k}");
		}
	}
    
	public function getLists( $isDeleted = false ) {
	    $status = I('status', 0, 'intval');
	    $page = $this->getPage();
	    $pageSize = $this->getPageSize();
	    $condition = array(
	        'a.status' => $status,
	        'a.to_agent' => $this->aid,
	    );
	    $d = M("AgentOrderSettle a")->join("__ORDER__ b on a.order_id=b.id", "LEFT")->join("__AGENT__ c on a.to_agent=c.id", "LEFT");
	    $settleList = $d->where($condition)->page($page)->limit($pageSize)->field("a.*,b.order_no,c.id as agent_id,c.name as agent_name")->select();
	    $count = $d->where($condition)->count();
	    $this->showPage($count, $pageSize);
	    $this->assign("settleList", $settleList);
	    $this->display();
	}
	
}